<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id
 * @property int $uid 用户ID
 * @property int $black_uid 拉黑用户ID
 * @property int $black_time 拉黑时间
 * @property int $black_status 0 拉黑 1 解除
 */
class UserBlacklist extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'tb_user_blacklist';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = [];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'uid' => 'integer', 'black_uid' => 'integer', 'black_time' => 'integer', 'black_status' => 'integer'];

    /**
     * 获取拉黑我的uid
     * @param $uid
     * @return array
     */
    public static function getBlackBarUids($uid)
    {
        // $sql = "SELECT uid,black_uid FROM {$this->table} WHERE black_uid = ? AND black_status= ?";
        // $pd = $this->createCommand($sql);
        // $pd->execute([$uid, 0]);
        // $list = $pd->fetchAll(PDO::FETCH_ASSOC);
        // return array_column($list, 'uid');
        return self::query()->where('black_uid', $uid)->where('black_status', 0)->pluck('uid')->toArray();

    }


    /**
     * 获取我拉黑的uid
     * @param $uid
     * @return array
     */
    public static function getBlackFooUids($uid)
    {
        // $sql = "SELECT uid,black_uid FROM {$this->table} WHERE uid = ? AND black_status= ?";
        // $pd = $this->createCommand($sql);
        // $pd->execute([$uid, 0]);
        // $list = $pd->fetchAll(PDO::FETCH_ASSOC);
        // return array_column($list, 'black_uid');
        return self::query()->where('uid', $uid)->where('black_status', 0)->pluck('black_uid')->toArray();

    }

}
